import { createStore } from 'vuex'
import persistedstate from "vuex-persistedstate";
export default createStore({
    state: {
        isLogin: false, //默认没有登录
        userInfo: null,
        token: null,
        //歌单播放列表
        tracks: [{
                id: 1939215517,
                al: {
                    id: 143632285,
                    name: "梁山伯与茱丽叶",
                    pic: 109951167308875650,
                    picUrl: "http://p3.music.126.net/jb6cZY3SwfzDg9v3tR97gg==/109951167308875648.jpg",
                    pic_str: "109951167308875648",
                }
            }

        ],
        playCurrentIndex: 0,
        audioInfo: {
            //音乐的播放状态
            audio: {},
            isPlay: false,
            //音量：0.2
            volume: 0.2
        },

        // actionSheet的配置
        actionSheetConfig: {
            isShow: true,
            list: [],
            successCallBack: null
        },
    },
    getters: {},
    mutations: {
        setPlayList(state, value) {
            state.tracks = value
        },
        setPlayIndex(state, value) {
            state.playCurrentIndex = value
        },
        prev(state, value) {
            state.playCurrentIndex -= 1
        },
        next(state, value) {
            state.playCurrentIndex += 1
        },
        //设置音频信息
        setPlay(state, value) {
            state.audioInfo.isPlay = value
        },
        setVolume(state, value) {
            state.audioInfo.volume = value
        },
        setAudio(state, value) {
            state.audioInfo.audio = value
        },


        showActionSheet(state, config) {
            state.actionSheetConfig.isShow = true;
            state.actionSheetConfig.list = config.list;
            state.actionSheetConfig.successCallBack = config.success
        },
        hideActionSheet(state) {
            state.actionSheetConfig.isShow = false;
            state.actionSheetConfig.list = []
            state.actionSheetConfig.successCallBack = null
        },
        login(state) {
            state.isLogin = true;
        },
        loginOut(state) {
            state.isLogin = false
            state.userInfo = null;
            state.token = null
        },
        setUserInfo(state, value) {
            state.userInfo = value
        },
        setToken(state, token) {
            state.token = token
        }
    },
    actions: {},
    modules: {},
    plugins: [persistedstate({
        storage: window.localStorage
    })],
})